package com.tedu.bill;

/**
 * Author：毕龙
 * Date: 2024/3/17 11:32
 */
public class TestString {
    public static void main(String[] args) {
        //声明一个String的变量
        String str = "林嘉伟";
        System.out.println(str);
        System.out.println("str地址："+System.identityHashCode(str));
        String str1 = "汪平安";
        System.out.println(str1);
        System.out.println("str1地址："+System.identityHashCode(str1));
        String str3 = "林嘉伟";
        System.out.println(str3);
        System.out.println("str3地址："+System.identityHashCode(str3));
        //JVM在遇到变量时 不会直接多运算
        String str4 = "林" ;
        String str5 = str4 + "嘉伟";
        System.out.println(str5);
        System.out.println("str5地址："+System.identityHashCode(str5));
        //JVM遇到字面值时  直接做运算
        String str6 = "林"+ "嘉伟";
        System.out.println(str6);
        System.out.println("str6地址："+System.identityHashCode(str6));
        System.out.println("==========================================");
        String str7 = "123";//123
        System.out.println(str7);
        System.out.println("str7地址："+System.identityHashCode(str7));
        //赋值运算符的右边执行的顺序 由左向右计算执行
        //str7是一个字符串 字符串和任意的类型相加都是字符串拼接
        //拼接以后任然是字符串类型
        str7 = str7+4+5+6;//123456
        System.out.println(str7);
        System.out.println("str7地址："+System.identityHashCode(str7));
        String str8 = "456";//456
        System.out.println(str8);
        System.out.println("str8地址："+System.identityHashCode(str8));
        //int + int  =>int + int => int + String => String
        str8 = 1 + 2 + 3 + str8;//6456
        System.out.println(str8);
        System.out.println("str8地址："+System.identityHashCode(str8));

    }
}
